package chatclient.applets.challengees;

import chatclient.applets.Chat;

import java.security.MessageDigest;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;

public class ChallengeePassword
        implements Challengee{
 
    @Override
    public byte[] getResponse(Chat chat, String digestSalt)
            throws Exception {
        
        JPasswordField passwordField = new JPasswordField();
        passwordField.setEchoChar('*');
        
        JOptionPane.showMessageDialog(null, passwordField, "Please enter your password:", JOptionPane.OK_OPTION);
        String password = String.valueOf(passwordField.getPassword());
        
        return MessageDigest.getInstance("MD5").digest((new StringBuilder(String.valueOf(digestSalt))).append(password).toString().getBytes("ISO-8859-1"));
    }

    /**
     * Gets the current user's password
     * @return Password scanned from message dialog input.
     * @throws Exception 
     */
    public String getPassword() {
        
        JPasswordField passwordField = new JPasswordField();
        passwordField.setEchoChar('*');
        
        JOptionPane.showMessageDialog(null, passwordField, "Please enter your password:", JOptionPane.OK_OPTION);
        
        return String.valueOf(passwordField.getPassword());
    }
}
